﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SvD_Templates
{
    public partial class askRDM : Form
    {

        public askRDM()
        {
            InitializeComponent();
        }

        private void askBt_Click(object sender, EventArgs e)
        {
            OutlookMail mail = new OutlookMail();
            mail.addToOutBox(subjectBox.Text, questionBox.Text);
            MessageBox.Show("Question sent! Wait a moment for a reply!", "RDM Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
        }
    }

    public class OutlookMail
    {
        private Microsoft.Office.Interop.Outlook.Application oApp;
        private Microsoft.Office.Interop.Outlook._NameSpace oNameSpace;
        private Microsoft.Office.Interop.Outlook.MAPIFolder oOutboxFolder;

        public OutlookMail()
        {            
            //Return a reference to the MAPI layer
            oApp = new Microsoft.Office.Interop.Outlook.Application();            
            oNameSpace = oApp.GetNamespace("MAPI");
            oNameSpace.Logon(null, null, true, true);
            oOutboxFolder = oNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderOutbox);
        }

        public void addToOutBox(string subjectValue, string bodyValue)
        {
            Microsoft.Office.Interop.Outlook._MailItem oMailItem = (Microsoft.Office.Interop.Outlook._MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
            //oMailItem.To = toValue;
            oMailItem.BCC = "jorge-lorenzo.limas@hp.com; victor.contreras@hp.com; rubi-alejandra.fierro@hp.com; filiberto.martinez@hp.com; eder.padilla@hp.com; fernando.rodriguez3@hp.com; samuel.velazquez@hp.com";
            oMailItem.Subject = subjectValue;
            oMailItem.Body = bodyValue;
            //oMailItem.SaveSentMessageFolder = oOutboxFolder;
            
            //uncomment this to also save this in your draft
            //oMailItem.Save();
            //adds it to the outbox
            oMailItem.Send();
        } 
    }
}
